<template>
	<view>
		<view class='login-from'>
			<view class='login-user'>绑定手机号 </view>
			<view class='login-user'>
				<text class='user-text'>手机号</text>
				<input type="text" v-model="phone" value="" placeholder="请输入手机号" />
			</view>

			<view class='login-user'>

				<input type="text" v-model="code" value="" placeholder="请输入验证码" />
			</view>
			<view class='login-user' @click="sendCode">


				<button type="primary">{{btnContent}}</button>

			</view>

			<button class='tel' @tap='bindTap'> 登录</button>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: "",
				code: "",
				btnContent: '获取验证码'
			}
		},
		methods: {
			// 获取验证码
			sendCode() {
				uni.request({
					url: "http://172.20.10.4:3000/api/sendMessage",
					header: {
						"Content-Type": "application/json;charset=utf-8"
						// "Content-Type":"application/x-www-form-urlencoded",
					},
					data: {
						mobile: this.phone|| '15923923999'
					},
					method: "GET",
					dataType: "json",

					success: (res) => {
						let datas = res
						let {
							code,
							yanma
						} = datas.data

						console.log("datas.data", datas.data)

console.log("datas.data", datas.data)
						if (code == 200) {
							this.code = yanma
						}
					},
					fail: res => {
						console.log("res", res)
					},
					complete: res => {}
				})

			},
			// 注册 登录
			bindTap() {
				uni.request({
					url: "http://172.20.10.4:3000/api/updateMobile",
					header: {
						"Content-Type": "application/json;charset=utf-8"
						// "Content-Type":"application/x-www-form-urlencoded",
					},
					data: {},
					method: "GET",
					dataType: "json",

					success: (res) => {
						let datas = res
						let {
							code,
							mobile
						} = datas.data

						console.log("datas.data", datas.data)


						if (code == 200) {
							this.phone = mobile

							uni.switchTab({
								url: "/pages/index/index"
							})


						}
					},
					fail: res => {
						console.log("res", res)
					},
					complete: res => {}
				})


			}


		}


	}
</script>

<style lang="scss">

</style>